package com.mmc.controller;

import com.mmc.result.R;
import com.mmc.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

/**
 * 作者：李嘉浩
 * 时间：2024-09-16-15:17
 * 功能：
 */

@RestController
@Api(tags = "文件上传")
@RequestMapping("/admin/file")
public class OssController {
    @Autowired
    private OssService ossService;

    @ApiOperation("文件上传")
    @PostMapping("/upload")
    public R upload(@RequestBody MultipartFile file) throws IOException {
        InputStream inputStream = file.getInputStream();
        String originalFilename = file.getOriginalFilename();
        String url=ossService.upload(inputStream,originalFilename);
        return R.ok().data("url",url);
    }
}
